package servlet;

import bean.Dog;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

/**
 * @author 东北
 * @date 2022/7/11
 * @apiNote
 */
@WebServlet("/dog")
public class DogServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建一个Dog集合
        List<Dog> dogs = new LinkedList<>();
        //添加元素
        dogs.add(new Dog("旺财",2,'公'));
        dogs.add(new Dog("旺福",3,'母'));
        dogs.add(new Dog("旺旺",4,'公'));
        dogs.add(new Dog("旺哈",5,'母'));
        dogs.add(new Dog("旺来",6,'公'));
        //添加到req中
        req.setAttribute("dogs",dogs);
        // 转发到dog.jsp文件
        req.getRequestDispatcher("dogs.jsp").forward(req,resp);
    }
}
